package store

import (
	"cmp"
	"context"
	"fmt"
	"server/internal/core/config"

	"github.com/redis/go-redis/v9"
)

var Redis *redis.Client

func initRedis(config *config.RedisConfig) error {
	Redis = redis.NewClient(&redis.Options{
		Addr:     fmt.Sprintf("%s:%d", cmp.Or(config.Host, "127.0.0.1"), cmp.Or(config.Port, 6379)),
		Password: config.Password,
		DB:       config.Database,
	})
	_, err := Redis.Ping(context.Background()).Result()
	if err != nil {
		return err
	}
	return nil
}
